package com.example.deepschool.service.Organization;

import com.example.deepschool.exception.CustomException;
import com.example.deepschool.repositories.OrganizationRepository;
import lombok.SneakyThrows;

public class OrganizationImpl implements Organization {
	
	private final OrganizationRepository organizationRepository;
	
	public OrganizationImpl (OrganizationRepository organizationRepository) {
		this.organizationRepository = organizationRepository;
	}
	
	@SneakyThrows
	@Override
	public Integer insert (com.example.deepschool.Model.Organization organization) {
		try {
			return organizationRepository.insert(organization);
		} catch (Exception e) {
			throw new CustomException(400, "组织添加失败");
		}
	}
	
	@SneakyThrows
	@Override
	public Integer delete (Long id) {
		try {
			return organizationRepository.delete(id);
		} catch (Exception e) {
			throw new CustomException(400, "组织删除失败");
		}
	}
	
	@SneakyThrows
	@Override
	public Integer update (com.example.deepschool.Model.Organization organization) {
		try {
			return organizationRepository.update(organization);
		} catch (Exception e) {
			throw new CustomException(400, "组织更新失败");
		}
	}
	
	@SneakyThrows
	@Override
	public com.example.deepschool.Model.Organization select (Long id) {
		try {
			return organizationRepository.select(id);
		} catch (Exception e) {
			throw new CustomException(400, "组织查询失败");
		}
	}
	
	@SneakyThrows
	@Override
	public com.example.deepschool.Model.Organization[] selectByName (String name) {
		try {
			return organizationRepository.selectByName(name);
		} catch (Exception e) {
			throw new CustomException(400, "组织查询失败");
		}
	}
}
